/**
 * 
 */
package org.youisoft.summer.evaluator.function.base;

import org.youisoft.summer.evaluator.InvokeException;
import org.youisoft.summer.evaluator.context.CalContext;
import org.youisoft.summer.evaluator.function.AbstractFunction;
import org.youisoft.summer.evaluator.operator.Operator;
import org.youisoft.summer.evaluator.operator.base.NullOperator;
import org.youisoft.summer.evaluator.operator.base.NumberOperator;
import org.youisoft.summer.evaluator.operator.base.StringOperator;

/**
 * @author zijiang.jl
 *
 */
public abstract class AbstractSingleFunction  extends AbstractFunction{
	private static final java.util.List<Class<?>> supports;
	static{
		supports=new java.util.ArrayList<Class<?>>();
		supports.add(NumberOperator.class);
		supports.add(StringOperator.class);
		supports.add(NullOperator.class);
	}
	
	
	@Override
	protected boolean checkOperator(int index, Operator<?> operator) {
		return supports.contains(operator.getClass());
	}
	
	
	
	@Override
	public <C, R, P> Operator<?> doInvoke(CalContext<C, R, P> context,
			Operator<?>... operator) throws InvokeException {
		if(operator[0] instanceof NullOperator) return operator[0];
		return this.doInvoke(context, operator[0].convertToNumberOperator());
	}



	protected abstract <C,R,P> Operator<?> doInvoke(CalContext<C,R,P> context,NumberOperator operator) throws InvokeException;



	@Override
	protected int minOperatorCount() {
		return 1;
	}
	
	
	
}
